package cn.yh.liu.action;

import java.util.HashMap;
import java.util.Map;

import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionSupport;

import cn.yh.liu.entity.Order;
import cn.yh.liu.entity.Page;
import cn.yh.liu.service.OrderService;
@Controller
public class OrderAction extends ActionSupport{
	
	private static final long serialVersionUID = 1L;
	private int pageIndex;
	private int pageSize;
	private Page<Order> page;
	private String name;
	private Double price;
	private int id;
	public int getId() {
		return id;
	}


	public void setId(int id) {
		this.id = id;
	}


	public String getName() {
		return name;
	}


	public void setName(String name) {
		this.name = name;
	}


	public Double getPrice() {
		return price;
	}


	public void setPrice(Double price) {
		this.price = price;
	}


	public Page<Order> getPage() {
		return page;
	}


	public void setPage(Page<Order> page) {
		this.page = page;
	}


	@Autowired
	private OrderService orderService;

	

	public OrderService getOrderService() {
		return orderService;
	}


	public void setOrderService(OrderService orderService) {
		this.orderService = orderService;
	}


	public int getPageIndex() {
		return pageIndex;
	}


	public void setPageIndex(int pageIndex) {
		this.pageIndex = pageIndex;
	}


	public int getPageSize() {
		return pageSize;
	}


	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}


	public String pageList(){
		Map<String,Object> map =new HashMap<String,Object>();
		map.put("PageIndex", pageIndex);
		map.put("PageSize", pageSize);
		page = orderService.findByPage(map);
		return SUCCESS;
		
	}
	public String addOrder(){
		Order order = new Order();
		order.setName(name);
		order.setPrice(price);
		orderService.addOrder(order);
		return SUCCESS;	
	}
	public String delOrder(){
		orderService.delById(id);
		return SUCCESS;	
	}
	public String findById(){
		Order order = orderService.findById(id);
		ServletActionContext.getRequest().setAttribute("orders", order);
		return SUCCESS;
		
	}
	public String editOrder(){
		Order order = new Order();
		order.setId(id);
		order.setName(name);
		order.setPrice(price);
		orderService.editOrder(order);
		return SUCCESS;
		
	}
}
